package cn.jji8.QSGUI.quick.tool;

import cn.jji8.QSGUI.quick.logger.Logger;
import org.bukkit.configuration.file.YamlConfiguration;

import java.util.List;

public class ConfgTool {
    /**
     * 获取配置文件中的对应key的string，没有就抛出错误
     * */
    public static String getString(YamlConfiguration yml, String key, String key1,String Default){
        return getString(yml,key,key1,Default,true);
    }
    public static String getString(YamlConfiguration yml, String key, String key1,String Default,boolean putSevere){
        String y = key+"."+key1;
        if(yml.contains(y)){
            return yml.getString(y);
        }
        if(putSevere){
            Logger.putSevere(yml.getName()+"中，"+key+"没有"+key1+"属性");
        }
        return Default;
    }
    public static int getint(YamlConfiguration yml, String key, String key1,int Default){
        return getint(yml,key,key1,Default,true);
    }
    public static int getint(YamlConfiguration yml, String key, String key1,int Default,boolean putSevere){
        String y = key+"."+key1;
        if(yml.contains(y)){
            return yml.getInt(y);
        }
        if(putSevere){
            Logger.putSevere(yml.getName()+"中，"+key+"没有"+key1+"属性");
        }
        Logger.putSevere(yml.getName()+"中，"+key+"没有"+key1+"属性");
        return Default;
    }
    public static List<String> getStringList(YamlConfiguration yml, String key, String key1,List<String> Default){
        return getStringList(yml,key,key1,Default,true);
    }
    public static List<String> getStringList(YamlConfiguration yml, String key, String key1,List<String> Default,boolean putSevere) {
        String y = key+"."+key1;
        if(yml.contains(y)){
            return yml.getStringList(y);
        }
        if(putSevere){
            Logger.putSevere(yml.getName()+"中，"+key+"没有"+key1+"属性");
        }
        Logger.putSevere(yml.getName()+"中，"+key+"没有"+key1+"属性");
        return Default;
    }
    public static boolean getBoolean(YamlConfiguration yml, String key, String key1,boolean Default){
        return getBoolean(yml,key,key1,Default,true);
    }
    public static boolean getBoolean(YamlConfiguration yml, String key, String key1,boolean Default,boolean putSevere) {
        String y = key+"."+key1;
        if(yml.contains(y)){
            return yml.getBoolean(y);
        }
        if(putSevere){
            Logger.putSevere(yml.getName()+"中，"+key+"没有"+key1+"属性");
        }
        Logger.putSevere(yml.getName()+"中，"+key+"没有"+key1+"属性");
        return Default;
    }
}
